package com.bl.weilan.api.controller.companyreport;

import com.bl.weilan.api.controller.BaseController;
import com.bl.weilan.common.ApiResponseBody;
import com.bl.weilan.dao.model.CompanyReportEntity;
import com.bl.weilan.service.biz.companyreport.CompanyReportService;
import com.bl.weilan.service.vo.DelBody;
import com.bl.weilan.service.vo.DelListBody;
import com.bl.weilan.service.vo.companyreport.CompanyReportAddVo;
import com.bl.weilan.service.vo.companyreport.CompanyReportListVo;
import com.bl.weilan.service.vo.companyreport.CompanyReportModVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

@RestController
@Log4j2
@RequestMapping(value = {"/weilan/apis/report"})
@Api(value = "公司新闻报道相关", description = "公司新闻报道相关api")
public class CompanyReportController extends BaseController {
    @Autowired
    CompanyReportService companyreportService;

    @ApiOperation(value = "根据公司id获取公司相关新闻报道列表信息", notes = "获取新闻报道列表信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "companyId", value = "公司id", required = true, paramType = "query", dataType = "String", defaultValue = ""),
            @ApiImplicitParam(name = "page", value = "页数", required = false, paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "size", value = "每页大小", required = false, paramType = "query", dataType = "int", defaultValue = "10")})
    @GetMapping(value = {"/get_list"})
    public ApiResponseBody<CompanyReportListVo> companyreportList(
            @RequestParam(value = "companyId", required = true, defaultValue = "") String companyId,
            @RequestParam(value = "page", required = false, defaultValue = "1") int page,
            @RequestParam(value = "size", required = false, defaultValue = "10") int size,
            HttpServletRequest request) {

        Pageable pageable = new PageRequest(page - 1, size);

        CompanyReportListVo companyreportListVo = companyreportService.getCompanyReportLists(companyId,pageable);

        return ApiResponseBody.createSuccessBody(companyreportListVo);
    }

    @ApiOperation(value = "获取一条公司相关新闻信息", notes = "获取一条公司新闻信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "query", dataType = "String")})
    @GetMapping(value = {"/get_detail"})
    public ApiResponseBody<CompanyReportListVo> companyreportList(
            @RequestParam(value = "id", required = true) String id,
            HttpServletRequest request) {

        CompanyReportEntity companyreportEntity = companyreportService.getCompanyReportById(id);

        return ApiResponseBody.createSuccessBody(companyreportEntity);
    }
}

